<?php
namespace Admin\Controller;
use Admin\Controller\CommonController;
use Think\Auth;
use Tools\Category;
class IndexController extends CommonController {
    public function index(){
    		$id=session('uid');
            $field=array('id','name','title','pid','target','rel');
            $auth=new Auth();
            $db=M('authrule');
            if($id==1){
                $result=$db->where(array('menu'=>1))->field($field)->order('sort')->select();
                $groups=$db->getField('id',true);
                foreach ($groups as $v) {
                    $rules .=$v.',';
                }
                $rules=rtrim($rules,',');
            }else{
                $groups=$auth->getGroups($id);
                foreach ($groups as $v) {
                    $rules .=$v['rules'].',';
                }
                $rules=rtrim($rules,',');
                $result=$db->where(array('id'=>array('in',$rules),'menu'=>1))->field($field)->order('sort')->select();
            }            
            session('rules',$rules);                           
            $menu=Category::unlimitedForLayer($result);
            $this->assign('rules',$rules);
            $this->assign('menu',$menu);
    		$this->display();
	    }
}